package impl

import face.ISomeService
import org.springframework.beans.factory.*

/**
 * Created by futao on 2017/9/29.
 */
class ISomeServiceImpl : ISomeService, BeanNameAware, BeanFactoryAware, InitializingBean, DisposableBean {
    private var aDao: String? = null

    private var bDao: String? = null

    //相当于java中的构造函数
    init {
        println("Step1:对象的创建.")
    }

    fun setaDao(value: String) {
        println("Step2:执行setaDao")
        this.aDao = value
    }

    fun setbDao(value: String?) {
        println("Step2:执行setbDao")
        this.bDao = value
    }

    /**
     * BeanNameAware
     */
    override fun setBeanName(p0: String?) {
        println("Step3:执行setBeanName，beanName=$p0")
    }

    /**
     * BeanFactoryAware
     */
    override fun setBeanFactory(p0: BeanFactory?) {
        println("step4:执行setBeanFactory，获取到beanFactory容器")
    }

    /**
     * InitializingBean
     * 标志着这个Bean初始化已经完毕了
     */
    override fun afterPropertiesSet() {
        println("step6:执行了afterPropertiesSet,标志着这个Bean初始化已经完毕了")
    }

    fun initAfter() {
        println("Step7:init-method-initAfter-初始化之后")
    }


    override fun doFirst(): String {
        println("Step9:执行业务逻辑代码-doFirst()方法")
        return "abcde"
    }

    /**
     * DisposableBean
     * 1.Bean要是单例的
     * 2.Bean容器要显示地关闭
     */
    override fun destroy() {
        println("Step10：准备销毁工作，进入销毁流程-DisposableBean")
    }

    fun beforeDestroy() {
        println("Step11：执行销毁之前，destroy-method")
    }

    override fun doSecond() {
        println("执行doSecond()方法")
    }
}
